package com.book.controller;

import com.book.service.BannerService;
import com.book.util.BaseResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 * @author auto
 * @since 2025-04-03 10:33:27
 */
@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;
    @GetMapping("")
    @ApiOperation(value = "获取轮播图")
    public BaseResult<?> getBannerImag() {
        return BaseResult.successResult(bannerService.getBannerList());
    }

    @PostMapping("")
    @ApiOperation(value = "上传轮播图")
    public BaseResult<?> uploadBanner(@RequestParam("fileUrl") String fileUrl) {
        return BaseResult.successResult(bannerService.saveBanner(fileUrl));
    }

    @PostMapping("/page/size")
    @ApiOperation(value = "分页查询数据库中的轮播图")
    public BaseResult<?> getBannerImagByPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        return BaseResult.successResult(bannerService.getBannerImagByPage(page, size));
    }

    @PostMapping("/enable/{id}")
    @ApiOperation(value = "启用轮播图")
    public BaseResult<?> enableBanner(@PathVariable("id") String id) {
        return BaseResult.successResult(bannerService.enableBanner(id));
    }

    @PostMapping("/disable/{id}")
    @ApiOperation(value = "禁用轮播图")
    public BaseResult<?> disableBanner(@PathVariable("id") String id) {
        return BaseResult.successResult(bannerService.disableBanner(id));
    }

}
